package com.tony.controller;

import com.tony.seavice.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private ContentService contentService;

    @RequestMapping({"/","/index"})
    public String index(){
        return "index";
    }

    @GetMapping("search/{keyword}/{pageNum}/{pageSize}")
    @ResponseBody
    public List<Map<String,Object>> search(@PathVariable String keyword,
                                           @PathVariable Integer pageNum,
                                           @PathVariable Integer pageSize){
        return contentService.search(keyword,pageNum,pageSize);
    }

    @GetMapping("load/{keyword}")
    @ResponseBody
    public Boolean loadData(@PathVariable String keyword){
        return contentService.loadData(keyword);
    }
}
